//
// IUT de Nice / Departement informatique / Module APO Java
// Annee 2011_2012 - Himalaya
//
// Classe T_Plateau_N1 - Tests unitaires des surcharges clone et equals
//
// Auteur : A.Marongiu et S. Guery
//
import java.util.*;

public class T_Plateau_N5 {

   public static void main (String[] args) {

      Tests.Begin("Himalaya.Plateau", "1.0.2");
	    //--- Village	
      	LinkedList<Ressource> listR = new LinkedList<Ressource>();
		Commande cmd = new Commande();
		Himalaya arbitre = new Himalaya();

		Village village1 = null;
		Village village2 = null;
		Village village3 = null;
		try {
			village1 = new Village(1,1,"",cmd,false,listR, arbitre);
			village2 = new Village(2,1,"",cmd,false,listR, arbitre);
			village3 = new Village(3,1,"",cmd,false,listR, arbitre);
		} catch (Throwable e) {
			e.printStackTrace();
		}

		Village[] tabVillage = new Village[3];
		
		tabVillage[0] = village1;
		tabVillage[1] = village2;
		tabVillage[2] = village3;
		
	// --- Sentiers
		Sentier sentier1 = new Sentier("terre",village1,village2);
		Sentier sentier2 = new Sentier("pierre", village2,village3);
		Sentier sentier3 = new Sentier("glace",village3,village1);

		Sentier matSentiers[][] = new Sentier[4][4];

		matSentiers[1][2] = sentier1; 
		matSentiers[2][3] = sentier2; 	
		matSentiers[3][1] = sentier3; 	
				
	// --- Regions
		ArrayList<Village> villagesR1 = new ArrayList<Village>();
		villagesR1.add(village1);
		villagesR1.add(village2);
		ArrayList<Village> villagesR2 = new ArrayList<Village>();
		villagesR2.add(village2);
		villagesR2.add(village3);
		ArrayList<Village> villagesR3 = new ArrayList<Village>();
		villagesR3.add(village3);
		villagesR3.add(village1);
		
		Region region1 = new Region(1,villagesR1);
		Region region2 = new Region(2,villagesR2);
		Region region3 = new Region(3,villagesR3);

		HashMap<Integer,Region>  HmapRegions = new HashMap<Integer,Region>();

		HmapRegions.put(1,region1);
		HmapRegions.put(2,region2);
		HmapRegions.put(3,region3);

		Plateau p = new Plateau(tabVillage,matSentiers,HmapRegions, arbitre);

         Tests.Design("Controle de la methode clone", 3); {
        	 Tests.Case("methode clone() : cas du constructeur par defaut"); {     		 
        		    Plateau p1 = new Plateau();
         			Plateau p2 = (Plateau)p1.clone();
         			
					Tests.Unit("Plateau\n"
							+ "[\n"
							+ "Villages = ( 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 )\n"
							+ "Sentiers = ( )\n"
							+ "Regions = ( )\n"
							+ "]", p2.toString());
         }

            Tests.Case("methode clone() : cas du constructeur normal"); {
            		
					Plateau p2 = (Plateau)p.clone();
            		Tests.Unit("Plateau\n"
								+ "[\n"
								+ "Villages = ( 1 2 3 )\n"
								+ "Sentiers = ( terre pierre glace )\n"
								+ "Regions = ( 1 2 3 )\n"
								+ "]", p2.toString());
            }
         }
         
         Tests.Design("Controle de la methode equals", 3); {
        	 Tests.Case("methode equals() : cas du constructeur par defaut"); {     		 
        		    Plateau p1 = new Plateau();
         			Plateau p2 = (Plateau)p1.clone();
         			Plateau p3 = new Plateau();
         			
         			Tests.Unit(true, p1.equals(p1));
					Tests.Unit(true, p1.equals(p2));
					Tests.Unit(true, p1.equals(p3));
					Tests.Unit(false, p1.equals(p));
         }

            Tests.Case("methode equals() : cas du constructeur normal"); {
            	//--- Village	
            	LinkedList<Ressource> listR2 = new LinkedList<Ressource>();
        		Commande cmd2 = new Commande();
        		Himalaya arbitre2 = new Himalaya();
		
    			Village village4 = null;
    			Village village5 = null;
    			Village village6 = null;
				try {
					village4 = new Village(4,1,"",cmd2,false,listR2, arbitre2);
        			village5 = new Village(5,1,"",cmd2,false,listR2, arbitre2);
        			village6 = new Village(6,1,"",cmd2,false,listR2, arbitre2);
				} catch (Throwable e) {
					e.printStackTrace();
				}
        		Village[] tabVillage2 = new Village[3];
        		
        		tabVillage2[0] = village4;
        		tabVillage2[1] = village5;
        		tabVillage2[2] = village6;
        		
        	// --- Sentiers
        		Sentier sentier4 = new Sentier("pierre",village1,village2);
        		Sentier sentier5 = new Sentier("glace", village2,village3);
        		Sentier sentier6 = new Sentier("terre",village3,village1);

        		Sentier matSentiers2[][] = new Sentier[4][4];

        		matSentiers2[1][2] = sentier4; 
        		matSentiers2[2][3] = sentier5; 	
        		matSentiers2[3][1] = sentier6; 	
        				
        	// --- Regions
        		ArrayList<Village> villagesR = new ArrayList<Village>();
        		villagesR.add(village1);
        		villagesR.add(village2);
        		ArrayList<Village> villagesR4 = new ArrayList<Village>();
        		villagesR4.add(village2);
        		villagesR4.add(village3);
        		ArrayList<Village> villagesR5 = new ArrayList<Village>();
        		villagesR5.add(village3);
        		villagesR5.add(village1);
        		
        		Region region4 = new Region(1,villagesR);
        		Region region5 = new Region(2,villagesR4);
        		Region region6 = new Region(3,villagesR5);

        		HashMap<Integer,Region>  HmapRegions2 = new HashMap<Integer,Region>();

        		HmapRegions2.put(1,region4);
        		HmapRegions2.put(2,region5);
        		HmapRegions2.put(3,region6);

        		Plateau p0 = new Plateau(tabVillage2,matSentiers2,HmapRegions2, arbitre);
        		Plateau p2 = (Plateau)p.clone();
        		
            		Tests.Unit(true,p.equals(p));
            		Tests.Unit(true,p.equals(p2));
            		Tests.Unit(false,p0.equals(p2));
            		Tests.Unit(false,p0.equals(p));
            		
            }
         }

      Tests.End();       
   }
}
